﻿using System;
using System.Collections.Generic;

using FlickrNet;

namespace Yorrick.FlickrMetadataSynchr.Events
{
    /// <summary>
    /// Class with event arguments for reporting the results of asynchronously processing metadata on Flickr.
    /// </summary>
    /// <typeparam name="TOut">The "out" metadata type that is the result of the asynchronous processing.</typeparam>
    public class AsyncFlickrWorkerEventArgs<TOut> : EventArgs
    {
        /// <summary>
        /// Gets the metadata. Is <c>null</c> when an error occurred. Setter is private.
        /// </summary>
        public TOut Metadata
        {
            private set;
            get;
        }

        /// <summary>
        /// Gets exception information if an error occurred. Is <c>null</c> when no error occurred. Setter is private.
        /// </summary>
        public Exception Error
        {
            private set;
            get;
        }

        /// <summary>
        /// Gets the sequence number. Setter is private.
        /// </summary>
        public int SequenceNumber
        {
            private set;
            get;
        }

        /// <summary>
        /// Gets or sets whether the operation should be cancelled.
        /// </summary>
        public bool Cancel
        {
            set;
            get;
        }

        /// <summary>
        /// Constructs a new instance for when <paramref name="metadata"/> was processed successfully.
        /// </summary>
        /// <param name="metadata">The <see cref="metadata"/> instance that was processed. Is not allowed to be <c>null</c>.</param>
        /// <param name="sequenceNumber">The sequence number in the list.</param>
        public AsyncFlickrWorkerEventArgs(TOut metadata, int sequenceNumber)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            Metadata = metadata;
            SequenceNumber = sequenceNumber;
        }

        /// <summary>
        /// Constructs a new instance for when an error occurred.
        /// </summary>
        /// <param name="metadata">The <see cref="metadata"/> instance that was processed. Is allowed to be <c>null</c>.</param>
        /// <param name="error">Exception information</param>
        /// <param name="sequenceNumber">The sequence number in the list.</param>
        public AsyncFlickrWorkerEventArgs(TOut metadata, Exception error, int sequenceNumber)
        {
            Metadata = metadata;
            Error = error;
            SequenceNumber = sequenceNumber;
        }
    }
}
